package com.ctshk.rpc.system.mapper;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ctshk.rpc.system.dto.SysBigClientQueryListDTO;
import com.ctshk.rpc.system.entity.SysBigClient;
import com.ctshk.rpc.system.req.SysBigClientQueryListReq;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 * 大客户 Mapper 接口
 * </p>
 *
 * @author 张志朋
 * @since 2021-02-03
 */
public interface SysBigClientMapper extends BaseMapper<SysBigClient> {


    /**
     * 大客户管理列表查询
     *
     * @param req 入参
     * @return 返回列表
     */
    @Select("<script>"+"select c.id id, c.cn_name groupCnName,c.en_name groupEnName,c.platform_sys_type platformSysType,c.status status,c.check_status checkStatus,c.modified_id modifiedId,c.gmt_modified gmtModified,su.cn_surname as cnSurname,su.cn_name as cnName from t_sys_big_client c left join t_sys_user su ON c.modified_id = su.id WHERE c.is_deleted = 0\n" +
            "<if test=\"req.groupName != null and req.groupName != ''\"> and (c.cn_name LIKE CONCAT('%',#{req.groupName},'%') or c.en_name LIKE CONCAT('%',#{req.groupName},'%'))</if> \n" +
            "<if test=\"req.status != null\"> AND c.status = #{req.status}</if> \n" +
            "<if test=\"req.checkStatus != null\"> AND c.check_status = #{req.checkStatus}</if> \n" +
            "<if test=\"req.id != null\"> AND c.id = #{req.id}</if> \n" +
            "<if test=\"req.platformSysType != null\"> AND c.platform_sys_type = #{req.platformSysType}</if> \n" +
            "<if test=\"req.isNotAdmin == 1\"> and c.create_id in <foreach collection=\"req.userIds\" item=\"item\" open=\"(\" close=\")\" separator=\",\">#{item}</foreach></if>\n" +
            "ORDER BY c.gmt_create DESC"+"</script>")
    IPage<SysBigClientQueryListDTO> queryList(@Param("req") SysBigClientQueryListReq req,IPage<SysBigClientQueryListDTO> page);

    @Update("UPDATE t_sys_big_client SET is_deleted = 1 WHERE id = #{id}")
    int deleteById(@Param("id") Long Id);
}
